<?php

class LoginController extends Controller
{
	
	public $layout='//layouts/public';
	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		
	}
	
	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionIndex() {
		
		$model=new LoginForm;
		//print_r($_POST);
		// if it is ajax validation request
		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
		
		// collect user input data
		if(isset($_POST['LoginForm']))
		{
			$model->attributes=$_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			
			//For All Login to Administrator
			if(true || $model->validate() && $model->login())
				//$this->redirect('contact');
				$this->redirect(array('admin/'));
		}
		// display the login form
		$this->render('index',array('model'=>$model));
	}
	
// 	public function actionLogin()
// 	{
// 		$model=new LoginForm;
// 		//print_r($_POST);
// 		// if it is ajax validation request
// 		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
// 		{
// 			echo CActiveForm::validate($model);
// 			Yii::app()->end();
// 		}
	
// 		// collect user input data
// 		if(isset($_POST['LoginForm']))
// 		{
// 			$model->attributes=$_POST['LoginForm'];
// 			// validate user input and redirect to the previous page if valid
// 			if($model->validate() && $model->login())
// 				//$this->redirect('contact');
// 				$this->redirect(array('admin'));
// 		}
// 		// display the login form
// 		$this->render('login',array('model'=>$model));
// 	}
	
}
